/*
 * Copyright 2010 JooKar (info@jookar.nl)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.jookar.gcodecommithook;

import static org.junit.Assert.*;

import nl.jookar.gcodecommithook.model.Commit;
import nl.jookar.gcodecommithook.model.Revision;

import org.junit.Test;

import com.google.gson.Gson;

// Sample JSON data: {"project_name":"Project name","repository_path":"Path to repository","revision_count":5,"revisions":[{"revision":1,"url":"URL","author":"Joost","timestamp":1295432737368,"message":"Revision 1","path_count":1,"added":["Added 1","Added 2"],"modified":["Modified 1"],"removed":["Removed 1"]},{"revision":2,"url":"URL","author":"Joost","timestamp":1295432745223,"message":"Revision 2","path_count":1,"added":["Added 1","Added 2"],"modified":["Modified 1"],"removed":["Removed 1"]}]}
/**
 * @author Joost A. Bloemsma
 *
 */
public class HookTest {
	@Test
	public void gsonTestSerialize() {
		Commit commit = new Commit();
		commit.setProjectName("test project");
		commit.setRepositoryPath("path to repository");
		//commit.setRevisionCount(2);
		Revision rev1 = new Revision();
		rev1.setMessage("commit message 1");

		Revision rev2 = new Revision();
		rev2.setMessage("commit message 2");

		commit.getRevisions().add(rev1);
		commit.getRevisions().add(rev2);
		Gson gson = new Gson();
		String json = gson.toJson(commit);
		System.out.println(json);
		Commit cm2 = gson.fromJson(json, Commit.class);
		assertEquals(commit.getProjectName(), cm2.getProjectName());
		assertEquals("rev list",commit.getRevisions().size(), cm2.getRevisions().size());
	}


}
